package net.aspw.client.features.module.impl.exploit

import net.aspw.client.event.EventTarget
import net.aspw.client.event.PacketEvent
import net.aspw.client.features.module.Module
import net.aspw.client.features.module.ModuleCategory
import net.aspw.client.features.module.ModuleInfo
import net.aspw.client.utils.InventoryUtils
import net.minecraft.network.play.client.C02PacketUseEntity
import net.minecraft.network.play.client.C03PacketPlayer

@ModuleInfo(
    name = "InfiniteDurability",
    spacedName = "Infinite Durability",
    category = ModuleCategory.EXPLOIT
)
class InfiniteDurability : Module() {
    private var attacked = false

    @EventTarget
    fun onPacket(event: PacketEvent) {
        if (event.packet is C02PacketUseEntity) {
            InventoryUtils.swap(9, mc.thePlayer.inventory.currentItem)
            InventoryUtils.swap(9, mc.thePlayer.inventory.currentItem)
            attacked = true
        }

        if (event.packet is C03PacketPlayer) {
            if (attacked) {
                InventoryUtils.swap(9, mc.thePlayer.inventory.currentItem)
                InventoryUtils.swap(9, mc.thePlayer.inventory.currentItem)
                attacked = false
            }
        }
    }
}